package it.lovaex.scb.unittests;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import it.lovaex.scb.Cart.CartItem;
import it.lovaex.scb.model.Item;

import org.junit.Test;

public class CartItemTest {

	private CartItem sut;
	private Item item = new Item("itemName", BigDecimal.TEN);
	private int quantity = 1;
	
	@Test
	public void test_get_Final_price() {
		BigDecimal expected = BigDecimal.valueOf(1*10);
		sut = new CartItem(quantity, item, BigDecimal.ZERO);
		assertEquals(expected, sut.getFinalPrice());
		assertEquals(BigDecimal.ZERO, sut.getDiscount());
		assertEquals(BigDecimal.TEN, sut.getUnitPrice());
		
		expected = BigDecimal.valueOf(1*10*(1-0.1));
		sut = new CartItem(quantity, item, BigDecimal.valueOf(0.1));
		assertEquals(expected, sut.getFinalPrice());
		assertEquals(BigDecimal.valueOf(0.1), sut.getDiscount());
		assertEquals(BigDecimal.TEN, sut.getUnitPrice());
	}
	
	@Test
	public void test_toString() {
		String expected = "itemName	| 1	| 10.00	| 0%	| 10.00\n";
		sut = new CartItem(quantity, item, BigDecimal.ZERO);
		assertEquals(expected, sut.toString());
		
		expected = "itemName	| 1	| 10.00	| 10%	| 9.00\n";
		sut = new CartItem(quantity, item, BigDecimal.valueOf(0.1));
		assertEquals(expected, sut.toString());
	}

}
